package com.nq.activaity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nq.activaity.dto.MbrLotteryPrizeShipmentResp;
import com.nq.activaity.entity.StMbrLotteryPrize;
import com.nq.activaity.entity.StMbrLotteryPrizeShipment;
import com.nq.activaity.service.IStMbrLotteryPrizeShipmentService;
import com.nq.common.Result;
import com.nq.common.State;
import com.nq.dao.activaity.StMbrLotteryPrizeMapper;
import com.nq.dao.activaity.StMbrLotteryPrizeShipmentMapper;
import com.nq.utils.DateTimeUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * @Description: 用户中奖发货表
 * @Author: jeecg-boot
 * @Date:   2024-11-05
 * @Version: V1.0
 */
@Service
public class StMbrLotteryPrizeShipmentServiceImpl extends ServiceImpl<StMbrLotteryPrizeShipmentMapper, StMbrLotteryPrizeShipment> implements IStMbrLotteryPrizeShipmentService {

    @Resource
    private StMbrLotteryPrizeMapper mbrLotteryPrizeMapper;



    @Override
    public IPage<MbrLotteryPrizeShipmentResp> queryPageList(Page<MbrLotteryPrizeShipmentResp> page, QueryWrapper<MbrLotteryPrizeShipmentResp> queryWrapper) {
        return baseMapper.queryPageList(page, queryWrapper);
    }

    @Override
    @Transactional
    public Result shipment(StMbrLotteryPrizeShipment shipment) {
        Date now = new Date();

        shipment.setShipmentTime(now);
        shipment.setState(StMbrLotteryPrizeShipment.STATE_1);
        baseMapper.updateById(shipment);

        // 更新抽奖表中的是否领取字段
        Integer lotteryPrizeId = shipment.getLotteryPrizeId();
        StMbrLotteryPrize prize = mbrLotteryPrizeMapper.selectById(lotteryPrizeId);
        if (null != prize) {
            prize.setReceiveTime(now);
            prize.setStatus(State.STATE_1);
            mbrLotteryPrizeMapper.updateById(prize);
        }
        return Result.OK();
    }


}